package com.hamizhong.iflowers.web.action.admin;

import com.hamizhong.iflowers.service.IAdminService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.web.base.MyBaseAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.AdminVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;

public class DoLoginADMAction extends MyBaseAction {

	private IAdminService iAdminService;
	
	public IAdminService getiAdminService() {
		return iAdminService;
	}
	public void setiAdminService(IAdminService iAdminService) {
		this.iAdminService = iAdminService;
	}

	@Override
	protected String doRequest() {		
		logger.info("----------------- Hello DoLoginADMAction -----------------");
		
		String loginName = (String) getRQ().getParameter("adminLoginName");
		String loginPassword = (String) getRQ().getParameter("adminLoginPassword");
		logger.info("loginName: "+loginName);
		logger.info("loginPassword: "+loginPassword);
		AdminVO adminVO = new AdminVO();
		adminVO.setLoginName(loginName);
		adminVO.setLoginPassword(loginPassword);
		IOPResultDto<IObjectVO> dto = iAdminService.doLoginADM(adminVO);
		if(dto.isSuccess()) {
			IObjectVO iObjectVO = (IObjectVO) dto.getFirstResult();
			AdminVO adminVOLogin = iObjectVO.getAdminVOList().get(0);
			getSSN().setAttribute(MyConstants.IFLOWERS_LOGIN_ADMIN_VO, adminVOLogin);
			return SUCCESS;
		}else {
			getRQ().setAttribute("errorMsg", dto.getErrorMSG());
			return "failed";
		}
	}

}
